#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define N 100005

int a[N], L[N], R[N], n, m, d[N];
vector<int> vt;

int main()
{
    for(int cas = 1; cas <= 10; cas++)
    {
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
            scanf("%d", &a[i]);
        vt.clear();
        for(int i = 0; i < n; i++)
        {
            int j = lower_bound(vt.begin(), vt.end(), a[i], less<int>()) - vt.begin();
            if(j == vt.size())
                vt.push_back(a[i]);
            else
                vt[j] = min(vt[j], a[i]);
            L[i] = j;
        }
        vt.clear();
        for(int i = n - 1; i >= 0; i--)
        {
            int j = lower_bound(vt.begin(), vt.end(), a[i], greater<int>()) - vt.begin();
            if(j == vt.size())
                vt.push_back(a[i]);
            else
                vt[j] = max(vt[j], a[i]);
            R[i] = j;
        }
        m = 0;
        for(int i = 0; i < n; i++)
            if(L[i] + R[i] > m) m = L[i] + R[i];
        int k(0);
        for(int i = 0; i < n; i++)
        {
            if(L[i]+R[i] == m)
            {
                d[k++] = a[i];
            }
        }
        sort(d, d+k);
        printf("%d\n", k);
        for(int i = 0; i < k; i++)
        {
            if(i != 0) putchar(' ');
            printf("%d", d[i]);
        }
        putchar('\n');
    }
    return 0;
}